
package com.joysuch.wwyt.edu.controller;

import com.joysuch.wwyt.core.bean.BaseUserFindAllBean;
import com.joysuch.wwyt.core.bean.BpUserSearchBean;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.edu.bean.*;
import com.joysuch.wwyt.edu.entity.EduCourseStatistics;
import com.joysuch.wwyt.edu.entity.EduExamRecord;
import com.joysuch.wwyt.edu.service.EduCourseStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 教育统计
 *
 * @Author ZhangDong
 * @Date 2020/6/24 17:32
 */
@Controller
@RequestMapping("/edu/courseware/statistics")
@Api(tags = "/edu/courseware/statistics 教育统计")
public class EduCourseStatisticsController {

    @Autowired
    private EduCourseStatisticsService eduCourseStatisticsService;

    @GetMapping("learnTime")
    @ApiOperation("添加课程学习时间")
    @ResponseBody
    public ResultBean learnTime(@RequestParam("courseawareId") Long courseawareId,
                                @RequestParam("learnTime") Integer learnTime, @RequestParam(value = "lastTime", required = false) Integer lastTime,
                                @RequestParam(value = "state", required = false, defaultValue = "0") Integer state,
                                @RequestParam(required = false) Long trainingId) {
        return eduCourseStatisticsService.learnTime(courseawareId, learnTime, lastTime, state,trainingId);
    }


    /**
     * 是否返回
     * @param courseawareId 课件id
     * @param learnTime 学习时长
     * @param isReturn 1学习结束 0继续学习
     * @param uuid  随机id
     * @return
     */
    @PostMapping("learnDocument")
    @ApiOperation("学习文档课件")
    @ApiImplicitParams({
            @ApiImplicitParam(required = true, paramType = "query", name = "courseawareId", value = "课件id"),
            @ApiImplicitParam(required = true, paramType = "query", name = "learnTime", value = "学习时长"),
            @ApiImplicitParam(required = true, paramType = "query", name = "isReturn", value = " 1学习结束 0继续学习"),
            @ApiImplicitParam(required = true, paramType = "query", name = "uuid", value = "随机id,每次打开文件产生"),
    })
    @ResponseBody
    public ResultBean learnDocument(@RequestBody EduLearnDocumentReqBean bean){
        return eduCourseStatisticsService.learnDocument(bean.getCourseawareId(), bean.getLearnTime(), bean.getIsReturn(), bean.getUuid(),bean.getTrainingId());
    }

    @GetMapping("user-learn-history")
    @ApiOperation("学习记录查询")
    @ResponseBody
    public ResultBean userLearnHistory(EduLearnHistoryBean bean) {
        return eduCourseStatisticsService.userLearnHistory(bean);
    }

    @GetMapping("learnHistory")
    @ApiOperation("学习历史查询")
    @ResponseBody
    public ResultBean learnHistory(EduCourseLearnHistoryBean bean) {
        return eduCourseStatisticsService.learnHistory(bean);
    }

    @GetMapping("exam-count-query")
    @ApiOperation(value = "app 个人学习时长，考试通过次数查询", response = EduCourseStatistics.class)
    @ResponseBody
    public ResultBean examCountQuery() {
        return eduCourseStatisticsService.examCountQuery();
    }

    @GetMapping("all-study-query")
    @ApiOperation(value = "所有人学习时长查询", response = EduCourseStatistics.class)
    @ResponseBody
    public ResultBean allStudyQuery(Pageable pageable) {
        return eduCourseStatisticsService.allStudyQuery(pageable);
    }

    @GetMapping("exam-count-web")
    @ApiOperation(value = "web端考试统计查询", response = EduExamCountDto.class)
    @ResponseBody
    public ResultBean examStatistics() {
        return eduCourseStatisticsService.examStatistics();
    }

    @GetMapping("record-query")
    @ApiOperation(value = "考试记录查询", response = EduExamRecordDto.class)
    @ResponseBody
    public ResultBean recordQuery(String userName) {
        return eduCourseStatisticsService.recordQuery(userName);
    }

    @PostMapping("exam-query-page")
    @ApiOperation(value = "考试分页查询", response = EduExamRecordPageDto.class)
    @ResponseBody
    public ResultBean examQueryPage(@RequestBody EduExamQueryBean bean) {
        return eduCourseStatisticsService.examQueryPage(bean);
    }

    @GetMapping("exam-absent-query")
    @ApiOperation("缺考人员查询")
    @ResponseBody
    public ResultBean examAbsentQuery(Long examId) {
        return eduCourseStatisticsService.examAbsentQuery(examId);
    }

    @GetMapping("exam-record-excel")
    @ApiOperation("考试记录excel导出")
    public void examRecordExcel(Long examId, HttpServletRequest request, HttpServletResponse response) {
        eduCourseStatisticsService.examRecordExcel(examId, request, response);
    }

    @GetMapping("exam-record-detail")
    @ApiOperation(value = "单个考试下所有考试记录查询", response = EduExamRecord.class)
    @ResponseBody
    public ResultBean examRecordDetail(Long examId, SearchEduExamRecordDetailBean condition, Pageable pageable) {
        return eduCourseStatisticsService.examRecordDetail(examId, condition, pageable);
    }

    @GetMapping("user-exam-record")
    @ApiOperation(value = "web 考试记录查询(人名)-记录条数分页查询", response = EduExamUserTotalDto.class)
    @ResponseBody
    public ResultBean userExamRecordPage(Long userId, int page, int size) {
        Pageable pageable = PageRequest.of(page, size);
        return eduCourseStatisticsService.userExamRecordPage(userId, pageable);
    }


    @GetMapping("user-exam-record-new")
    @ApiOperation(value = "web 考试记录查询(人名)-记录条数分页查询", response = EduExamUserTotalDto.class)
    @ResponseBody
    public ResultBean userExamRecordNewPage(Long userId, int page, int size) {
        Pageable pageable = PageRequest.of(page, size);
        return eduCourseStatisticsService.userExamRecordNewPage(userId, pageable);
    }


    @GetMapping("learner-course-statistics-export")
    @ApiOperation(value = "查询课程下学员学习状态-导出", response = BaseUserFindAllBean.class)
    public void learnerCourseStatisticsExport(Long courseId, BpUserSearchBean condition, HttpServletRequest request, HttpServletResponse response) {
        eduCourseStatisticsService.learnerCourseStatisticsExport(courseId, condition, request, response);
    }

    @GetMapping("learner-course-statistics")
    @ApiOperation(value = "查询课程下学员学习状态", response = BaseUserFindAllBean.class)
    @ResponseBody
    public ResultBean learnerCourseStatistics(Long courseId, BpUserSearchBean condition, Pageable pageable) {
        return eduCourseStatisticsService.learnerCourseStatistics(courseId, condition, pageable);
    }

}
